package com.ruoyi.TraditionalCultureSys.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.Anonymous;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.TraditionalCultureSys.domain.TraditionalBuildings;
import com.ruoyi.TraditionalCultureSys.service.ITraditionalBuildingsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 历史建筑Controller
 * 
 * @author ruoyi
 * @date 2024-06-24
 */
@RestController
@RequestMapping("/TraditionalCultureSys/buildings")
public class TraditionalBuildingsController extends BaseController
{
    @Autowired
    private ITraditionalBuildingsService traditionalBuildingsService;

    /**
     * 查询历史建筑列表
     */
    @PreAuthorize("@ss.hasPermi('list')")
    @GetMapping("/list")
    public TableDataInfo list(TraditionalBuildings traditionalBuildings)
    {
        startPage();
        List<TraditionalBuildings> list = traditionalBuildingsService.selectTraditionalBuildingsList(traditionalBuildings);
        return getDataTable(list);
    }

    /**
     * 导出历史建筑列表
     */
    @PreAuthorize("@ss.hasPermi('export')")
    @Log(title = "历史建筑", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TraditionalBuildings traditionalBuildings)
    {
        List<TraditionalBuildings> list = traditionalBuildingsService.selectTraditionalBuildingsList(traditionalBuildings);
        ExcelUtil<TraditionalBuildings> util = new ExcelUtil<TraditionalBuildings>(TraditionalBuildings.class);
        util.exportExcel(response, list, "历史建筑数据");
    }

    /**
     * 获取历史建筑详细信息
     */
    @PreAuthorize("@ss.hasPermi('query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(traditionalBuildingsService.selectTraditionalBuildingsById(id));
    }

    /**
     * 新增历史建筑
     */
    @PreAuthorize("@ss.hasPermi('add')")
    @Log(title = "历史建筑", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TraditionalBuildings traditionalBuildings)
    {
        return toAjax(traditionalBuildingsService.insertTraditionalBuildings(traditionalBuildings));
    }

    /**
     * 修改历史建筑
     */
    @PreAuthorize("@ss.hasPermi('edit')")
    @Log(title = "历史建筑", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TraditionalBuildings traditionalBuildings)
    {
        return toAjax(traditionalBuildingsService.updateTraditionalBuildings(traditionalBuildings));
    }

    /**
     * 删除历史建筑
     */
    @PreAuthorize("@ss.hasPermi('remove')")
    @Log(title = "历史建筑", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(traditionalBuildingsService.deleteTraditionalBuildingsByIds(ids));
    }

    /**
     *
     * @return 全部历史建筑信息
     */
    @Anonymous
    @ResponseBody
    @RequestMapping(value = "/getAllTraditionalBuildings", produces = {"application/json;charset=utf-8"})
    public AjaxResult getAllTraditionalBuildings() {
        List<TraditionalBuildings> traditionalBuildings = traditionalBuildingsService.getAllTraditionalBuildings();
        return AjaxResult.success("traditionalBuildings",traditionalBuildings);
    }



}
